<template>
	<view class="container">
		<!-- 头部信息 -->
		<view class="top">
			<view class="shop-info">
				<view class="shop-name">
					<text class="name">{{shop.shop_name}}</text>
					<text>编号：{{shop.tenant_serial}}</text>
				</view>
				<view class="all-but">
					<button class="user-but" @click="switchTab('/pages/user/user')">个人中心</button>
					<view class="check-but">
						<button @click="getadmin">查看后台</button>
						<button class="chil-two" @click="continued(false)">续租</button>
					</view>
				</view>
			</view>
		</view>

		<!-- 抽奖乐透 -->
		<view class="luck" @click="navTo('/pages/luckdraw/luckdraw')">
			<view class="today-luck">
				<view class="lucky-l">
					<image :src="luckgoods.cover_img" mode=""></image>
				</view>
				<view class="lucky-r">
					<text class="tit">今日乐透奖励</text>
					<text class="goods-tit">商品名：{{luckgoods.title}}</text>
					<text class="goods-money">价格：<text class="money">{{luckgoods.goods_price}}</text>元</br></text>
				</view>
			</view>
		</view>

		<!-- 管理 -->
		<view class="operation" v-if="status !== 'overdue'">
			<view class="operation-o" @click="cash()">
				<uni-icons type="icon-tixian1" color="#ff3333" size="43" class="icon"></uni-icons>
				<text class="text-ad">提现</text>
			</view>
			<view class="operation-o" @click="navTo('/pages/shopadmin/goodsadmin')">
				<uni-icons type="icon-shangpinguanli1" color="#ab67ff" size="43" class="icon"></uni-icons>
				<text class="text-ad">商品管理</text>
			</view>
			<view class="operation-o" @click="navTo('/pages/shopadmin/buymember')">
				<uni-icons type="icon-huiyuanguanli" color="#ff9f23" size="43" class="icon"></uni-icons>
				<text class="text-ad">消费会员</text>
			</view>
		</view>
        <!-- 店铺收益 -->
        <view class="all-shopprofit">
          <view class="shop-profit">
            <view class="top-shop">
              <span>店铺收益</span>
            </view>
            <view class="profit-all">
              <view class="profit-num">
                <span class="t-one">{{info.dayIncome}}</span>
                <span class="t-two">今日收益</span>
              </view>
              <view class="profit-num">
                <span class="t-one">{{info.monthIncome}}</span>
                <span class="t-two">近30天收益</span>
              </view>
              <view class="profit-num">
                <span class="t-one">{{info.allIncome}}</span>
                <span class="t-two">累计收益</span>
              </view>
              <view class="profit-num">
                <span class="t-one">{{info.balance}}</span>
                <span class="t-two">可用金额</span>
              </view>
            </view>
          </view>
        </view>
        
        
        <!-- 商铺销量 -->
            <view class="all-shopprofit">
              <view class="shop-profit">
                <view class="top-pro">
                  <span>我的销量</span>
                  <span style="color: #BFBEBE;font-size: 13px;"
                        @click="goadmin()">详情请查看后台</span>
                </view>
                <view class="money-all">
                  <view class="time-profit">
                    <span class="check"
                          @click="getshop('day')"
                          :class=" key =='day'? 'in-check' : 'check' ">今天</span>
                    <span class="check"
                          @click="getshop('week')"
                          :class=" key =='week'? 'in-check' : 'check' ">近7天</span>
                    <span class="check"
                          @click="getshop('month')"
                          :class=" key =='month'? 'in-check' : 'check' ">近30天</span>
                    <span class="check"
                          @click="getshop('all')"
                          :class=" key =='all'? 'in-check' : 'check' ">累计</span>
                  </view>
                  <view class="money-profit">
                    <view class="all-info">
                      <span class="t-one">{{info.Salesnum}}</span>
                      <span class="t-two">订单数</span>
                    </view>
                    <view class="all-info">
                      <span class="t-one">{{info.Salesmoney}}</span>
                      <span class="t-two">订单金额</span>
                    </view>
                  </view>
                </view>
              </view>
            </view>
		<view class="operation_no" v-if="status == 'overdue'">
			<text>店铺已到期 , 请续租继续使用...</text>
		</view>
	</view>
</template>

<script>
	import share from '@/components/share';
	import uniIcons from '../../ed-icons/ed-icons.vue'
	import {
		getOne,
        postOne
	} from '../../api/publicapi.js'

	export default {
		components: {
			share,
			uniIcons
		},
		data() {
			return {
				shopid: [],
				status: [],
				shop:{
					shop_name:'',
					tenant_serial:''
				},
				luckgoods: [],
				page: 1,
                info:{},
                key:'day'
			};
		},
		async onLoad(options) {
			// console.log(options.id)
			this.shopid = options.id
		},
		onShow() {
			this.getshop('day')
		},
		methods: {
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (this.user === null) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},
			switchTab(url) {
				uni.switchTab({
					url
				})
			},

			getshop(key) {
                uni.showLoading({
                    title: '加载中'
                });
                this.key = key
				getOne('front/storeapply/getstore',{key:key}).then(res => {
					// 店铺过期状态查询
					this.status = res.data.status
					// 店铺信息
					this.shop = res.data.tenant
					// 乐透商品
					this.luckgoods = res.data.shop

                    this.info = res.data
                      uni.hideLoading()
				})
			},
			cash() {
				uni.showModal({
					content: '该功能正在内测中！',
					showCancel: false
				});
			},
			continued (whether = false) {
			      let params = {
			        whether: whether,
                    type:'minipayment'
			      }
                  uni.showLoading({
                      title: '检测支付环境'
                  })
                  let  that  = this
			      postOne('front/storeapply/poststore',params).then(res => {
               
			               if(res.message == '成功'){
			                   let data = res.data
                               
			                   uni.getProvider({
			                       service: 'oauth',
			                       success: function (res) {
			                           data.provider = res.provider[0]
			                           that.wxpay(data)
			                           uni.hideLoading();
			                       }})
			               }else{
			                   that.$api.msg(res.message )
			               }
			      	
			      	})
			      },
			      wxpay(data){
			      	console.log(data)
			          let that = this
			          uni.requestPayment({
			              appId:data.appId,
			              provider: data.provider,
			              timeStamp: data.timestamp,
			              nonceStr: data.nonceStr,
			              package: data.package,
			              signType: data.signType,
			              paySign: data.paySign,
			              success: function (res) {
			                  that.$api.msg('续租成功')
			                  that.continued(true)
			                  
			              },
			              fail: function (err) {
			                  // that.$api.msg('续租成功')
                              // that.continued(true)
                              
			              }
			          });
			      },
                  // front/storeapply/showadmin
                  getadmin() {
                    
                         let newTime = new Date().getTime() + 3600000 * 12;//新的过期时间

                      if(!this.panduan()){
                          return
                      }
                  	getOne('front/storeapply/showadmin').then(res => {
                  		
                       let data =  JSON.parse(res.data.response)
                       
                       if(data.error_code==0){
                           this.$api.msg('请留意短信通知')
                           uni.setStorageSync('showadmin', newTime);
                       }
                       
                  	
                  	})
                  },
                 panduan(){
                     let currentTime = Date.parse(new Date()); //当前时间戳
                     let SetTimeStr = uni.getStorageSync('showadmin') * 1;
                  
                     if (currentTime < SetTimeStr) {
                        
                        this.$api.msg('距离上次查看未过12小时')
                          return false
                        
                     } else {  
                       return true
                     }
                 }

		},

	}
</script>

<style lang='scss'>
	page {
		background: #f7f7f7;
	}

	/* 头部 */
	.top {
		width: 100%;
		height: 401upx;
		background: url('https://edsfiles.oss-cn-shenzhen.aliyuncs.com/%E5%B0%8F%E7%A8%8B%E5%BA%8F/shopcenter.png') no-repeat;
		background-size: 100%;

		.shop-name {
			text-align: center;
			color: #fff;
			padding-top: 105upx;
			padding-bottom: 24upx;

			.name {
				font-size: 40upx;
			}

			text {
				display: block;
				font-size: 30upx;
			}
		}

		.all-but {
			display: flex;
			justify-content: space-between;
			width: 90%;
			margin: 0 auto;
			padding-bottom: 32upx;

			.user-but {
				margin-top: 52upx;
			}

			.chil-two {
				margin-top: 30upx;
			}

			button {
				margin: 0;
				padding: 0;
				font-size: 27upx;
				width: 150upx;
				height: 63upx;
				line-height: 63upx;
				color: #595959;
			}
		}
	}


	.luck {
		width: 100%;
		height: 100%;
		padding: 25upx 0;
		background: #fff;
		margin-top: 25upx;

		.today-luck {
			width: 90%;
			margin: 0 auto;
			display: flex;

			.lucky-l {
				width: 250upx;
				height: 180upx;
				float: left;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.lucky-r {
				float: left;
				font-size: 30upx;
				padding-left: 40upx;
				width: 80%;

				.money {
					color: #d23931;
				}

				.tit {
					display: block;
					font-size: bold;
				}

				.goods-tit {
					display: block;
					padding: 20upx 0;
					font-size: 25upx;
					overflow: hidden;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					color: #595959;
				}

				.goods-money {
					font-size: 26rpx;
					color: #595959;
				}
			}
		}
	}

	.operation {
		display: flex;
		justify-content: space-between;
		width: 93%;
		margin: 0 auto;
		padding-top: 22upx;

		.operation-o {
			width: 31%;
			height: 230upx;
			text-align: center;
			background: #fff;
			border-radius: 15upx;
			webkit-box-shadow: 0upx 6upx 8upx #e2e2e2;
			box-shadow: 0upx 6upx 8upx #e2e2e2;

			.text-ad {
				font-size: 31upx;
				color: #595959;
			}

			.icon {
				display: block;
				padding-top: 42upx;
				padding-bottom: 20upx;
			}
		}
	}

	.operation_no {
		width: 100%;
		text-align: center;
		padding-top: 50upx;
	}
    .all-shopprofit {
      width: 100%;
      margin: 0 auto;
      background: #fff;
      margin-top: 15px;
    }
    .shop-profit {
      width: 92%;
      margin: 0 auto;
      padding-top: 12px;
      padding-bottom: 15px;
    }
    .top-shop {
      padding-bottom: 10px;
      border-bottom: 1px solid #dfdfdf;
      font-size: 15px;
    }
    .profit-num {
      padding-top: 11px;
    }
    .t-one {
      display: block;
      font-size: 17px;
      font-weight: 500;
      padding-bottom: 2px;
    }
    .t-two {
      font-size: 11px;
      color: #bfbebe;
    }
    .top-pro {
      padding-bottom: 10px;
      border-bottom: 1px solid #dfdfdf;
      display: flex;
      justify-content: space-between;
      font-size: 15px;
    }
    .profit-all {
      width: 100%;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      text-align: center;
    }
    .time-profit {
      width: 92%;
      display: flex;
      justify-content: space-between;
      margin: 0 auto;
      font-size: 15px;
    }
    .check {
      padding-top: 14px;
      padding-bottom: 12px;
      color: #bfbebe;
      font-weight: bold;
    }
    .in-check {
      font-weight: bold;
      padding-top: 14px;
      padding-bottom: 12px;
      border-bottom: 2px solid #d23931;
      color: #d23931;
    }
    .money-profit {
      display: flex;
      justify-content: space-evenly;
      height: 100px;
      border: 1px solid #dfdfdf;
      margin-top: 7px;
    }
    .all-info {
      width: 50%;
      text-align: center;
      padding-top: 27px;
    }

</style>
